//
//  ByContactCustomerVC.m
//  caipiao_ios
//
//  Created by mc on 2018/7/11.
//  Copyright © 2018年 ZhangZhanbin. All rights reserved.
//

#import "ByContactCustomerVC.h"

@interface ByContactCustomerVC ()

@property (nonatomic, strong) UILabel *valueLabel;

@end

@implementation ByContactCustomerVC

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self addLeftBackBarButtonItem];
    self.title = @"联系客服";
    
    [self initViews];
    // Do any additional setup after loading the view.
}


- (void)initViews{
    
    
    [ByApiOther configAppSuccess:^(ByNetBaseResult *result) {
        NSLog(@"APP配置信息查询 %@", result.data);
        NSArray *array = result.data[@"data"];
        NSUserDefaults * userDefaults = [NSUserDefaults standardUserDefaults];
        if ([array isKindOfClass:[NSArray class]]) {
            for (int i = 0; i < array.count; i++) {
                NSDictionary *dic = [array objectAtIndex:i];
                if ([dic[@"name"] isEqualToString:@"service"]) {
                    [userDefaults  setObject:dic[@"value"] forKey:KEY_SERVICE_INFO];
                    self.valueLabel.text = dic[@"value"];
                }
            }
        }
        [userDefaults synchronize];
        
    } failure:^(ByNetBaseResult *result) {
        [ByCoreToolAlert showFailureWithText:result.msg];
    }];
    
    self.view.backgroundColor = BY_BACKGROUND_COLOR;
    
    UIView *backgroundView = [[UIView alloc] init];
    [self.view addSubview:backgroundView];
    [backgroundView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view).offset(5);
        make.top.equalTo(self.view).offset(10);
        make.right.equalTo(self.view).offset(-5);
        make.height.mas_equalTo(@65);
    }];
    backgroundView.backgroundColor = [UIColor whiteColor];
    backgroundView.layer.cornerRadius = 10;
    
    
    UILabel *titleLabel = [[UILabel alloc] init];
    [backgroundView addSubview:titleLabel];
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(backgroundView).offset(13);
        make.top.equalTo(backgroundView).offset(14);
        make.size.mas_equalTo(CGSizeMake(120, 15));
    }];
    
    titleLabel.font = FONT(13);
    titleLabel.textColor = [UIColor blackColor];
    titleLabel.text = @"客服热线";

    UILabel *valueLabel = [[UILabel alloc] init];
    [backgroundView addSubview:valueLabel];
    [valueLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(titleLabel.mas_left).offset(0);
            make.right.equalTo(backgroundView).offset(-120);
            make.bottom.equalTo(backgroundView).offset(-14);
           make.height.mas_equalTo(@16);
    }];
    valueLabel.textColor = [UIColor blackColor];
    valueLabel.font = FONT(14);
    NSUserDefaults * userDefaults = [NSUserDefaults standardUserDefaults];
    NSString *service =  [userDefaults objectForKey:KEY_SERVICE_INFO];
    valueLabel.text = [NSString stringWithFormat:@"%@", service];
    self.valueLabel = valueLabel;
    
    UIButton *phoneBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [backgroundView addSubview:phoneBtn];
    [phoneBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(backgroundView).offset(-15);
        make.centerY.equalTo(backgroundView).offset(0);
        make.size.mas_equalTo(CGSizeMake(25, 25));
    }];
    
    [phoneBtn setImage:[UIImage imageNamed:@"kefurexian"] forState:UIControlStateNormal];
    [phoneBtn addTarget:self action:@selector(phoneAction:) forControlEvents:UIControlEventTouchUpInside];
}

- (void)phoneAction:(UIButton *)btn{
    NSUserDefaults * userDefaults = [NSUserDefaults standardUserDefaults];
    NSString *service =  [userDefaults objectForKey:KEY_SERVICE_INFO];
    NSMutableString * str=[[NSMutableString alloc] initWithFormat:@"tel:%@",service];
    UIWebView * callWebview = [[UIWebView alloc] init];
    [callWebview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:str]]];
    [self.view addSubview:callWebview];
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
